function hideDiv(div_id){
            $("#" + div_id).animate({opacity: "hide" }, 300);
}
function popupDiv(div_id) {
            var div_obj = $("#" + div_id);
            //窗口宽度,高度
            var winWidth = $(window).width();
            var winHeight = $(window).height();
            //弹出的div的宽度,高度
            var popHeight = div_obj.height();
            var popWidth = div_obj.width();
            div_obj.animate({
				 opacity: "show", left: (winWidth-popWidth) / 2, top: (winHeight-popHeight)/2,width:popWidth,height:popHeight}, 300);          
}
$(function() {
            $("#AddCertificate_div").easydrag();
            $("#AddCertificate_div").setHandler("#AddCertificate_div #AddCertificate_head");
});
$(function() {
    $("#UpdateCertificate_div").easydrag();
    $("#UpdateCertificate_div").setHandler("#UpdateCertificate_div #UpdateCertificate_head");
});




$(function()
{
	dwrCertificateManager.getAllDuty(function(data)
			{
		for ( var i = 0; i < data.length; i++) {
			$("#afterduty").append(
					"<option value='" + data[i].id + "'>"
							+ data[i].name + "</option>");
		}
		});
	dwrCertificateManager.getAllDept(function(data)
			{
		for ( var i = 0; i < data.length; i++) {
			$("#afterdept").append(
					"<option value='" + data[i].id + "'>"
							+ data[i].name + "</option>");
		}
			});
	
});
function clickaddcer()
{
	if(!RolePowerManager())
	{
		return;
	}
	popupDiv('AddCertificate_div');
	//$("#empno").focus();
}

function clickupdate(id)
{
	dwrCertificateManager.getCertificateById(id,function(data)
			{
				$("#upcerid").val(data.id);
				$("#upempno").html(data.emp.empno);
				$("#upempname").html(data.emp.name);
				$("#uptrainname").html(data.train.trainname);
				$("#upcername").val(data.cername);
				$("#upcerno").val(data.cerid);
				$("#upcerdate").val(data.cerdate);
				$("#updateline").val(data.deadline);
				$("#oldsalary").html(data.emp.salary);
				$("#beforedept").html(data.emp.dept.name);
				$("#beforeduty").html(data.emp.duty.name);				
			});
	popupDiv('UpdateCertificate_div');
}
function updateCertificate()
{
	if(!RolePowerManager())
	{
		return;
	}
	$("#updateform").submit();
}
function search()
{
	if($("#starttime").val()||$("#endtime").val()||""!=$("#starttime").val()||""!=$("#endtime").val())
		{
			$("#serchtype").val("time");
			$("#searchform").submit();
		}else
			{
			$("#searchform").submit();
			}
}

function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="FindCertificateServlet?pageSize="+pageSize;
}
function checkempno()
{
	dwrCertificateManager.getEmpIdByEmpNo($("#empno").val(),function(data)
			{
				if(data)
					{
						dwrCertificateManager.getEmpByEmpNo($("#empno").val(),function(data)
								{
									$("#empname").html(data.name);
								});
						
					}else
						{
							alert("员工不存在");
						}
			});
}

function checktrainid()
{
	dwrCertificateManager.getTrainById($("#trainid").val(),function(data)
			{
				if(data)
					{
						$("#trainname").html(data.trainname);
					}else
						{
						alert("培训不存在");
						}
			});	
}

function addCertificate()
{
	if($("#empno").val()||$("#trainid").val()||$("#cername").val()||$("#cerid").val()||$("#cerdate").val()||$("#dateline").val())
		{
				
				GetEmpTrainManager.getByEmpNoAndTrainId($("#empno").val(),$("#trainid").val(),function(d)
				{
					if(d.sum<60)
						{
							alert("成绩不合格");							
						}else
							{
								$("#addcerform").submit();
								alert("添加成功");
							}
							
				});
				
		}else
			{
				alert("请保持信息的完整性");
			}
}

function changeserchtype()
{
	if($("#serchtype").val()=="time")
		{
		$("#inputtext").animate({opacity : "hide"}, 500);
		}else
			{
			$("#inputtext").animate({opacity : "show"}, 500);
			}
}
function deletecer(id)
{
	if(!RolePowerManager())
	{
		return;
	}
	if(!confirm("是否确定删除 ？"))
	{
		return;
	}
	dwrCertificateManager.deleteById(id,function(data)
			{
				if(data)
					{
						alert("删除成功！");
						location.href="FindCertificateServlet";
					}
				else
					{
						alert("删除失败！");
					}
			});
}